<template>
	<Row>
		<ICol span="24">
			<Button type="info" @click="choiseKeyword">选择关键词</Button>
		</ICol>
		<ICol span="24" style="margin-top: 25px;">
			<ITable :columns="columns" :data="data" v-show="data.length>0"></ITable>
		</ICol>
		<ModalKeyword ref="keyword" :callback="getKeyword"></ModalKeyword>
	</Row>
</template>
<script>
	import {Row,Col,Button,Table} from 'iview';

	import ModalKeyword from 'admin/components/wechat/function/reply/reply-item/modal-list-keyword';

	export default{
		props:{
			callback:{
				type:Function,
				required : true,
			}
		},
		components:{
			Row,
            'ICol':Col,
            Button,
            ModalKeyword,
            'ITable' : Table,
		},
		data(){
			return {
				columns: [
                    {
                        title: '规则名',
                        key: 'ruleName'
                    },
                    {
                        title: '关键词',
                        key: 'keyword'
                    },
                    {
                        title: '回复类型',
                        key: 'replyType'
                    },
                ],
                data :[],
			}
		},
		methods:{
			//打开关键词modal
			choiseKeyword(){
				this.$refs.keyword.modal = true;
			},
			setKeyword(id){
				this.getKeyword(id);
			},
			//获得选中的关键词
			getKeyword(id){
				this.Axios.Wechat.Function.Reply.Get(id)
	            .then(res =>{
	                if(!res) return false;
	                var data = res.data,
	                	typeArr = {mpnews:'图文消息',text:'文本',image:'图片'};
	                this.data = [];
	                this.data.push({
	                	ruleName : data.ruleName,
	                	keyword : data.keyword,
	                	replyType : typeArr[data.reply.replyType]
	                });
	                this.callback(id);
	            })
			}
		},
	}
</script>